/* $Id: Formatters.java 101 2010-12-26 21:25:55Z altdotua@gmail.com $ */

package alt.djudge.frontend.server.utils;

import java.util.Date;
import java.util.TimeZone;

import alt.djudge.frontend.server.datatypes.SubmissionEntry;
import alt.djudge.frontend.server.datatypes.scores.ProblemUserScoreEntry;

public class Formatters
{
	
	public static Date getUserTime(Date gmtTime, TimeZone zone)
	{
		return gmtTime;
	}
	
	public static String formatJudgement(String j)
	{
		if ("CE".equalsIgnoreCase(j))
			return "Помилка компіляції";
		if ("RE".equalsIgnoreCase(j))
			return "Помилка часу виконання";
		if ("TLE".equalsIgnoreCase(j))
			return "Ліміт часу";
		if ("MLE".equalsIgnoreCase(j))
			return "Ліміт памяті";
		if ("AC".equalsIgnoreCase(j))
			return "Зараховано";
		if ("WA".equalsIgnoreCase(j))
			return "Неправильна відповідь";
		if ("N/A".equalsIgnoreCase(j))
			return "-";
		return j;
	}
	
	public static String formatMonitorCell(SubmissionEntry s)
	{
		if (s == null)
			return "<td>-</td>";
		if ("AC".equals(s.getJudgement()))
			return "<td bgcolor='#aaffaa'><a href='" + Linker.link("submission.jsp?submission_id=" + s.getId()) + "'><b>" + s.getScore() + "</b></a></td>";
		return "<td><a href='" + Linker.link("submission.jsp?submission_id=" + s.getId()) + "'>" + s.getScore() + "</a></td>";
	}
	
	public static String formatContestTime(Long minutes)
	{
		if (minutes == null)
			return "??:??";
		Long days = minutes / 60 / 24;
		Long hours = (minutes / 60) % 24;
		minutes %= 60;
		if (days == 1)
			return "" + days + " day " + hours + ":" + (minutes  >= 10 ? minutes : "0" + minutes);
		if (days > 1)
			return "" + days + " day(s) " + hours + ":" + (minutes  >= 10 ? minutes : "0" + minutes);
		return hours + ":" + (minutes  >= 10 ? minutes : "0" + minutes);
	}
	
	public static String formatContestTimeSeconds(Long second)
	{
		return formatContestTime(second / 60) + ":" + ((second % 60 > 10) ? second % 60 : "0" + (second % 60));
	}
	
	public static String formatMonitorCell(ProblemUserScoreEntry s)
	{
		if (s.getAcceptedCount() == 0 && s.getRejectedCount() == 0 && s.getPendingCount() == 0)
			return "<td>-</td>";
		if (s.getAccepted())
			return "<td bgcolor='#aaffaa'><a href='" + Linker.link("submission.jsp?submission_id=" + s.getMaxScoreId()) + "'><b>" + s.getMaxScore() + "</b></a></td>";
		else if (s.getPendingCount() > 0)
			return "<td bgcolor='#ffffaa'>-</td>";
		return "<td><a href='" + Linker.link("submission.jsp?submission_id=" + s.getMaxScoreId()) + "'>" + s.getMaxScore() + "</a></td>";
	}
	
	
	public static String formatMonitorCellACM(ProblemUserScoreEntry s)
	{
		if (s.getAcceptedCount() == 0 && s.getRejectedCount() == 0 && s.getPendingCount() == 0)
			return "<td>-</td>";
		if (s.getAccepted())
			return "<td bgcolor='#aaffaa'><a href='" + Linker.link("submission.jsp?submission_id=" + s.getMaxScoreId()) + "'><b>" + (s.getRejectedCount() == 0 ? "+" : "+" + s.getRejectedCount()) + "</b></a></td>";
		return "<td bgcolor='" + (s.getPendingCount() > 0 ? "#ffffaa" : "#ffaaaa") + "'><a href='" + Linker.link("submission.jsp?submission_id=" + s.getMaxScoreId()) + "'><b>" + "-" + s.getRejectedCount() + "</b></a></td>";
	}	
}

